<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    评论:<input type="text"/>
    <ol></ol>
    <script>
var c = console.log;
var input = document.querySelector("input")
var ol = document.querySelector("ol");
input.addEventListener(
"keyup",
function(ev){
    if(ev.key === "Enter"){
if(input.value.length===0){
    alert("输入框为空，提交失败");
    return;
}
var li = document.createElement("li");
li.innerHTML = input.value+"<button onclick='del(this)'>删除</button>";
if(ol.childElementCount === 0){
    ol.appendChild(li);
}else{
    ol.insertBefore(li,ol.firstElementChild);

}
input.value = null;

    }
}

);
function del(ele){
    return confirm("是否删除？")?ele.parentNode.parentNode.removeChild(ele.parentNode) : false;
}



    </script>
</body>
</html>
